<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ include file="../Main/top.jsp"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="/WEB-INF/CustomTag" prefix="customTag"%>
<script type="text/javascript" src="MajorFileSrcCate.js"></script>
<script type="text/javascript">
	$(document).ready( function() {
		majorFileCateParentIdChange();
		isPreCategoryClick();
	});
	
	//父分类ID改变激活事件
	function majorFileCateParentIdChange() {
		$("#majorFileCateParentId").change(function() {
			if ($("#majorFileCateParentId").attr("value") != -1) {
				getParentCateIsPre();
				$("#majorId").removeClass("required");			
			} else if ($("#majorFileCateParentId").attr("value") == -1) {
				$("#isPreCategory0").attr("checked", false)
				$("#isPreCategory1").attr("checked", false)
				$("#isPreCategoryLine").show();
				$("#majorIdLine").show();
				$("#majorIdNull").attr("selected",true);
				$("#depth").attr("value",1);
				$("#majorId").addClass("required");
			}
		});
	}

	//获取是否为预置分类并根据其设置当前分类值
	function getParentCateIsPre(){
		var majorFileCateParentId = document.getElementById("majorFileCateParentId").value;
		if(majorFileCateParentId!=""){
			$.post(
					"../AjaxResultData/checkParentCateIsPre.action",
					{"majorFileSrcCate.majorFileCateId":majorFileCateParentId},
					function(data){
						var isNotUsedData = eval("("+data.isNotUsedData+")");
						if(isNotUsedData[0].isNotUsed==0){
							$("#isPreCategory0").attr("checked", true);
							$("#isPreCategoryLine").hide();
							$("#majorIdLine").hide();
						}else if(isNotUsedData[0].isNotUsed==1){
							$("#isPreCategory1").attr("checked", true);
							$("#isPreCategoryLine").hide();
							$("#majorIdNull").attr("selected",true);
							$("#majorIdLine").hide();
						}
						$("#majorId").attr("value",isNotUsedData[0].cateId);
						$("#depth").attr("value",(parseInt(isNotUsedData[0].parentDepth)+1));
						//alert($("#majorId option:selected").attr("value"));
					},
					"json"
			);
		}
	}
	
	function isPreCategoryClick(){
		$("#isPreCategory1").click(function(){
			$("#majorIdNull").attr("selected",true);
			$("#majorIdLine").hide();
			$("#majorId").removeClass("required");
		});
		$("#isPreCategory0").click(function(){
			$("#majorIdLine").show();
			$("#majorId").addClass("required");
		});
	}
</script>
<div class="function_title"><span class="t2"><img src="../images/dqwz.gif">当前位置：添加分类（专业文件资源）</span></div>
<div class="function_content">
<div class="addItem"><img src="../images/return_icon.png"><a href="listMajorFileSrcCate.action?intercept=1">返回列表</a></div>

<div class="bigRed">添加分类时，只有从属于根分类的一级分类可以设置是否为预置分类,其他子分类根据其父分类自动设置!</div>
<div class="important_info">注：带*项为必填信息!</div>
<form action="insertMajorFileSrcCate.action" method="post" id="demo" >
<input type="hidden" name="majorFileSrcCate.author" id="majorFileSrcCate.author" value="<s:property value="#session.userName" />"> 
<input type="hidden" name="majorFileSrcCate.depth" id="depth" value="1"> 
 <table width="100%" border="0" cellpadding="0" cellspacing="0" class="loginTable">
    <tr>
      <td width="14%" align="right" class="leftBg"><span class="important_info">*</span>分类名称：</td>
      <td width="86%"><input type="text" name="majorFileSrcCate.majorFileCateName" id="majorFileSrcCate.majorFileCateName"></td>
    </tr>
    <tr>
      <td align="right" class="leftBg"><span class="important_info">*</span>所属父分类：</td>
      	<td>
<customTag:treeSelector majorFileCateId="${majorFileSrcCate.majorFileCateParentId}" type="majorFileSrcCate" selectName="majorFileCateParentId" notNeedValidation="false" target="false"></customTag:treeSelector>
		</td>
    </tr>
    <tr id="isPreCategoryLine">
      <td align="right" class="leftBg"><span class="important_info">*</span>是否为预置分类：</td>
      <td>
<input type="radio" name="majorFileSrcCate.isPreCategory" value="1" class="no_border" id="isPreCategory1">是
<input type="radio" name="majorFileSrcCate.isPreCategory" value="0" class="no_border" id="isPreCategory0">否
<span id="errMsg"></span>
</td>
    </tr>
    <tr id="majorIdLine">
      <td align="right" class="leftBg"><span class="important_info">*</span>所属专业：</td>
      <td>
		<select name="majorFileSrcCate.majorId" id="majorId" class="required">
			<option value="" id="majorIdNull">--未选择--</option>
			<s:iterator value="listMajor" status="stat">
				<option value="<s:property value='majorId'/>"><s:property value='majorName'/></option>
			</s:iterator>
		</select>
	</td>
    </tr>
    <tr>
      <td align="right">&nbsp;</td>
      <td>
        <input type="submit" name="submit" id="submit" value="提交" class="deal_button">
      </td>
    </tr>
  </table>
</form>

</div>

<%@ include file="../Main/bottom.jsp"%>

